//
//  UIView+HUD.m
//  MengCP
//
//  Created by uplooking on 16/8/12.
//  Copyright © 2016年 LiZhenning. All rights reserved.
//

#import "UIView+HUD.h"
#import "MBProgressHUD.h"
#import <objc/runtime.h>
#import "Macros.h"

#import "RTSpinKitView.h"

static const void *HttpRequestSKVKey = &HttpRequestSKVKey;

static const void *HttpRequestHUDKey = &HttpRequestHUDKey;

static const void *HttpRequestSKVBgKey = &HttpRequestSKVBgKey;

@implementation UIView (HUD)

- (void)showHint:(NSString *)hint
{
   
    //显示提示信息
    UIView *view = [[UIApplication sharedApplication].delegate window];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.userInteractionEnabled = NO;
    // Configure for text only and offset down
    hud.mode = MBProgressHUDModeText;
    hud.label.text = hint;
    hud.label.backgroundColor = [UIColor clearColor];
    hud.label.textColor = [UIColor whiteColor];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor blackColor];
    hud.margin = 10.f;
    hud.yOffset = 200.f  * kAutoScanleX;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
    
}
#pragma mark

- (MBProgressHUD *)HUD{
    return objc_getAssociatedObject(self, HttpRequestHUDKey);
}

- (void)setHUD:(MBProgressHUD *)HUD{
    objc_setAssociatedObject(self, HttpRequestHUDKey, HUD, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)showHudInView:(UIView *)view hint:(NSString *)hint{
    
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:view];
    HUD.label.text = hint;
    HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    //设置等待框背景色为黑色
    HUD.bezelView.backgroundColor = [UIColor blackColor];
    HUD.removeFromSuperViewOnHide = YES;
    [UIActivityIndicatorView appearanceWhenContainedIn:[MBProgressHUD class], nil].color = [UIColor whiteColor];
    [view addSubview:HUD];
    [HUD showAnimated:YES];
    [self setHUD:HUD];
}

- (void)hideHud{
    [[self HUD] hide:YES];
}



@end
